/*
 * @lc app=leetcode.cn id=520 lang=cpp
 *
 * [520] 检测大写字母
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    bool isAlpha(char c)
    {
        return c >= 'A' && c <= 'Z';
    }

public:
    bool detectCapitalUse(string word)
    {
        if (word.size() <= 1)
            return true;
        if (isAlpha(word[0]))
        {
            if (isAlpha(word[1]))
            {
                for (int i = 2; i < word.size(); i++)
                {
                    if (!isAlpha(word[i]))
                        return false;
                }
            }
            else
            {
                for (int i = 1; i < word.size(); i++)
                {
                    if (isAlpha(word[i]))
                        return false;
                }
            }
        }
        else
        {
            for (int i = 1; i < word.size(); i++)
            {
                if (isAlpha(word[i]))
                    return false;
            }
        }
        return true;
    }
};
// @lc code=end
